package com.lifo.good.service.serviceimpl;

import com.lifo.good.bean.model.HfGoodDescription;
import com.lifo.good.dao.SearchHfGoodDescriptionMapper;
import com.lifo.good.service.SearchHfGoodDescriptionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

/**
 * Created by Administrator on 2018/5/15 0015.
 */
@Service
@Slf4j
public class SearchHfGoodDescriptionServiceImpl implements SearchHfGoodDescriptionService {

    @Autowired
    private SearchHfGoodDescriptionMapper searchHfGoodDescriptionDao;

    @Override
    public HfGoodDescription searchHfGoodDescriptionByHfUid(int hfGoodId) {
        HfGoodDescription hfGoodDescription = null;
        try {
            hfGoodDescription =  searchHfGoodDescriptionDao.searchHfGoodDescriptionByHfGoodId(hfGoodId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return  hfGoodDescription;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public void updateHfGoodDescriptionByHfUid(@Param(value = "hfUid") int hfUid, @Param(value = "goodInfo") String goodInfo) {
        try {
            searchHfGoodDescriptionDao.updateHfGoodDescriptionByHfUid(hfUid,goodInfo);
        }catch (Exception e){
            log.error("更新商品详情内容失败==>{}",e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
        }
    }

    @Override
    public List<HfGoodDescription> getHfGoodDescriptionsTop100ByIsClear(int isClear) {
        List<HfGoodDescription> hfGoodDescriptionList = null;
        try {
            hfGoodDescriptionList = searchHfGoodDescriptionDao.getHfGoodDescriptionsTop100ByIsClear(isClear);
        }catch (Exception e){
            log.error("获取商品详情内容前100失败==>{}",e.getMessage());
            e.printStackTrace();
        }
        return hfGoodDescriptionList;
    }
}
